(* counter derivation combined with button *)
MEM ledr = 1136, buttonr = 1140;
CONST ledm = 8; (* for nano 9k replace with 64 *)
VAR led;

PROCEDURE delay;
    VAR cnt;
BEGIN
    cnt := 0;
    WHILE cnt < 50000 DO
        cnt := cnt + 1
    END
END;

BEGIN
    led := 0;
    WHILE 1 = 1 DO
        IF buttonr = 1 THEN
            led := led + 1;
            IF led = ledm THEN
                led := 1
            END;
            ledr := led;
            
            CALL delay
        ELSE
            led := 0;
            ledr := 0
        END
    END
END.
